package com.map.lbs;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

public class MessageActivity extends Activity {
	private CommentsListAdapter adapter;
	@Override
    public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.message);
		
		Intent intent = getIntent();
		long messageId = intent.getLongExtra("message_id", -1);
		
		if(messageId != -1){
			MessageFactory factory = new MockMessageFactory();
			Message message = factory.get(messageId);
			
			if(message != null){
				TextView title = (TextView)findViewById(R.id.message_title);
				title.setText(message.getLocationDesc());
				ImageView photo = (ImageView) findViewById(R.id.message_photo);
				photo.setBackgroundResource(R.drawable.face);
				TextView author = (TextView) findViewById(R.id.message_author);
				author.setText(message.getAuthor());
				TextView content = (TextView) findViewById(R.id.message_content);
				content.setText(message.getSnippet());
				TextView time = (TextView)findViewById(R.id.message_time);
				time.setText(message.getTime().toLocaleString());
				
				adapter = new CommentsListAdapter(message.getComments(), this);
				ListView commentList = (ListView) findViewById(R.id.list_comment);
				commentList.setAdapter(adapter);
			}
		}
		
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event){
		if(keyCode == KeyEvent.KEYCODE_BACK){
			Intent intent = new Intent();
			intent.setClass(MessageActivity.this, MapStageActivity.class);
			
			startActivity(intent);
			MessageActivity.this.finish();
			return true;
		}
		return false;
	}
}
